*****load the data file titled rep_data_August2023.dta
use rep_data_August2023

****Table 2: Existence of a written script for an indigenous language and official language choice



bysort Script_N: tab LP_any_colonial if sampledef==1
bysort Script_N: tab LP_any_indigenous if sampledef==1


***Figure 3: Linguistic diversity and official language choice
reg ln_lang i.LP_any_colonial if Script_N==1 & sampledef==1
margins i.LP_any_colonial, post
margins, coeflegend
estimates store W12

 
reg ln_lang i.LP_any_indigenous if Script_N==0 & sampledef==1
margins i.LP_any_indigenous, post
margins, coeflegend
estimates store W22


coefplot (W12, keep(1.LP_any_colonial)) ///
(W12, keep(0.LP_any_colonial)) ///
, vertical  nooffsets recast(bar) barwidth(0.8) fcolor(*.8) ///
citop ciopts(recast(rcap))  mlabel mlabcolor(black) ///
coeflabels(, notick labgap(2)) plotregion(margin(b=0)) ylabel(, nogrid labsize(zero)) bgcolor(white) graphregion(color(white)) level(90) ///
format(%9.2f) addplot(scatter @b @at, ms(i) mlabel(@b) mlabpos(8) mlabcolor(black)  mlabsize(large)) ///
xlabel(, labsize(zero)) title("Panel A""Sample of countries with written tradition" "Colonial language co-official?", size(medium) color (black)) ///
ytitle("Log no. of languages", ///
size(medium) color(black))  ///
 legend(order(1 "Yes" 3 "No") cols(2))  /// 
 saving(wt0.gph, replace)

coefplot (W22, keep(1.LP_any_indigenous)) ///
(W22, keep(0.LP_any_indigenous)) ///
, vertical  nooffsets recast(bar) barwidth(0.8) fcolor(*.8) ///
citop ciopts(recast(rcap))  mlabel mlabcolor(black) ///
coeflabels(, notick labgap(2)) plotregion(margin(b=0)) ylabel(, nogrid labsize(zero)) bgcolor(white) graphregion(color(white)) level(90) ///
format(%9.2f) addplot(scatter @b @at, ms(i) mlabel(@b) mlabpos(8) mlabcolor(black)  mlabsize(large)) ///
xlabel(, labsize(zero)) title("Panel B""Sample of countries without written tradition" "Indigenous language co-official?", size(medium) color (black)) ytitle("Log no. of languages", ///
size(medium) color(black))  ///
 legend(order(1 "Yes" 3 "No") cols(2))  /// 
 saving(wt2.gph, replace)
 
 
grc1leg wt0.gph wt2.gph ,   cols(2)  legendfrom(wt0.gph ) graphregion(color(white)) xcommon  saving(LD_LP3, replace)
graph export LD_LP3.pdf, replace



***Table 3: Existence of written script, linguistic diversity and language policy: OLS Regressions


reg LP_any_colonial script_lnnlang  ln_lang Script_N rootstuber_suitabilty cereal_suitabilty  AsiaNew AmericaN colony_gbr colony_fra colony_prt rugged soil desert tropical dist_coast near_coast RiveraccessX100 areakm  Npmispc23x10k japn_occupied_ww2 if sampledef==1 , robust 
outreg2 using ols1.tex, stats(coef se ) auto(2)   paren(se) bracket (ci) level(95) label replace


reg LP_any_indigenous script_lnnlang  ln_lang Script_N rootstuber_suitabilty cereal_suitabilty AsiaNew AmericaN  colony_gbr colony_fra colony_prt rugged soil desert tropical dist_coast near_coast RiveraccessX100 areakm  Npmispc23x10k japn_occupied_ww2 if sampledef==1 , robust 
outreg2 using ols1.tex, stats(coef se ) auto(2)  paren(se) bracket (ci) level(95) label append




****Figure 4: The paired comparisons on language policy

graph twoway  ///
             (scatter lang_fragm1 Dist_Min_MMC1 if quartiles_dist_swt!=. & sampledef==1 , mlabel(pwtcountry) mcolor(black) mlabcolor(black) mlabposition(12) )  ///
			 , ylabel(, nogrid) bgcolor(white) graphregion(color(white))  saving(vignettes, replace) 
graph export vignettes.pdf, replace		 			 
			 

